//
//  CellTableViewForYouJi.m
//  SeeTheWorld
//
//  Created by dllo on 16/1/20.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellTableViewForYouJi.h"
#import <UIImageView+WebCache.h>
#import "ModelOfShouYeCell.h"

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@interface CellTableViewForYouJi ()

@property (nonatomic, retain)UIImageView *imageBackGround;
@property (nonatomic, retain)UILabel *labelOfTitle;
@property (nonatomic, retain)UIImageView *imageOfTouXiang;
@property (nonatomic, retain)UILabel *labelOfStartDate;

@property (nonatomic, retain)UIView *viewOfBack;


@end

@implementation CellTableViewForYouJi

- (void)dealloc {
    [_imageBackGround release];
    [_labelOfTitle release];
    [_imageOfTouXiang release];
    [_labelOfStartDate release];
    [super dealloc];
}

#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageBackGround = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageBackGround];
        [_imageBackGround release];
        
        self.viewOfBack = [[UIView alloc] init];
        [self.contentView addSubview:self.viewOfBack];
        [_viewOfBack release];
        self.viewOfBack.backgroundColor = [UIColor blackColor];
        self.viewOfBack.alpha = 0.1;
        
        self.labelOfTitle = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelOfTitle];
        [_labelOfTitle release];
        self.labelOfTitle.textColor = [UIColor whiteColor];
        self.labelOfTitle.font = [UIFont systemFontOfSize:19];
        self.labelOfTitle.numberOfLines = 0;
        
        self.labelOfStartDate = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelOfStartDate];
        [_labelOfStartDate release];
        self.labelOfStartDate.textColor = [UIColor whiteColor];
        self.labelOfStartDate.font = [UIFont systemFontOfSize:16];
        
        self.imageOfTouXiang = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageOfTouXiang];
        self.imageOfTouXiang.backgroundColor = [UIColor redColor];
        [_imageOfTouXiang release];
        self.imageOfTouXiang.userInteractionEnabled = YES;
        
    }
    return self;
}

#pragma mark - 赋值
- (void)passModel:(ModelOfShouYeCell *)model {
   
    self.labelOfTitle.text = model.name;
    [self.imageBackGround sd_setImageWithURL:[NSURL URLWithString:model.front_cover_photo_url] placeholderImage:[UIImage imageNamed:@"1f178a82b9014a90e9109296ad773912b31beeeb"]];
    
    [self.imageOfTouXiang sd_setImageWithURL:[NSURL URLWithString:[model.user objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"1f178a82b9014a90e9109296ad773912b31beeeb"]];
    
    self.labelOfStartDate.text = [NSString stringWithFormat:@"%@  / %ld天  / %ld图", model.start_date, (long)model.days, (long)model.photos_count];
}

#pragma mark - 布局子视图
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.imageBackGround.frame = CGRectMake(10, 10, WIDTH - 20, self.contentView.frame.size.height - 20);
    self.viewOfBack.frame = self.imageBackGround.frame;
    
    self.labelOfTitle.frame = CGRectMake(15, 15, WIDTH - 30, 40);
    
    self.imageOfTouXiang.frame = CGRectMake(15, self.contentView.frame.size.height - 15 - self.contentView.frame.size.height / 4, self.contentView.frame.size.height / 4, self.contentView.frame.size.height / 4);
    self.imageOfTouXiang.layer.cornerRadius = self.contentView.frame.size.height / 4 / 2;
    self.imageOfTouXiang.layer.masksToBounds = YES;
    
    self.labelOfStartDate.frame = CGRectMake(15, 15 + 40, self.contentView.frame.size.width - 30, 20);
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
